#include "CFGConfig.h"
using namespace xml_api;

CCFGConfig& CCFGConfig::Instance()
{
  static CCFGConfig instance;
  return instance;
}

CCFGConfig::CCFGConfig()
{

}

bool CCFGConfig::SaveState(Memento* m)
{
  m->SetName("Config");

  Memento* c = m->CreateChild("Source");
  m_source.SaveState(c);

  c = m->CreateChild("Date");
  m_date.SaveState(c);

  c = m->CreateChild("Destination");
  for(ARR_CCFGDestination::size_type i = 0; i < m_destinations.size(); ++i)
  {
    m_destinations[i].SaveState(c);
  }

  return true;
}

bool CCFGConfig::LoadState(Memento* m)
{
  int child_num=m->GetChildCount();
  for(int i=0; i<child_num; ++i)
  {
    Memento* child_m=m->GetChild(i);
    std::string child_name = child_m->GetName();
    if("Source" == child_name)
    {
      m_source.LoadState(child_m);
    }
    else if("Date" == child_name)
    {
      m_date.LoadState(child_m);
    }
    else if("Destination" == child_name)
    {
      CCFGDestination des;
      des.LoadState(child_m);
      m_destinations.push_back(des);
    }
  }

  return true;
}